﻿Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Data
Public Class add
    'ประกาศตัวแปรตัวเชื่อมต่อ
    Dim sql As MySqlConnection
    Dim ipconnect As String
    Dim usernamedb As String
    Dim dbname As String
    Dim mysqlpass As String
    Dim id_user As String
    Dim position_user As String
    Public Sub New(ByRef mysql_pass As String, ByRef ip_connect As String, ByRef user_namedb As String, ByRef db_name As String)
        InitializeComponent()
        mysqlpass = mysql_pass
        ipconnect = ip_connect
        usernamedb = user_namedb
        dbname = db_name
    End Sub
    ''โค้ดปุ่มsave monitor
    Private Sub btnsavemonitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavemonitor.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Try
            mySqlCommand.CommandText = "INSERT INTO data_device (type,name,model,m_size,detail,serialnumber,price,state_device,date,idDepartment) VALUES ('Monitor','" & tab1model.Text & "', '" & tab1brand.Text & "', '" & tab1size.Text & "','" & tab1detail.Text & "','" & tab1serial.Text & "','" & tab1price.Text & "','ว่าง','" + Date.Now.ToString + "','0');"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! BY โตน ลูกพี่อารี")

            ''เคลียร์ช่องหลังกรอกเสร็จ

            tab1model.Text = ""
            tab1brand.Text = ""
            tab1size.Text = ""
            tab1detail.Text = ""
            tab1serial.Text = ""
            tab1price.Text = ""
        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try
    End Sub
    ''โค้ดปุ่มsave computer
    Private Sub btnsavecom_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavecom.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim computerhims As String
        Dim computerpacs As String
        Dim computerlab As String
        Dim computersystem As String
        Dim computeradmin As String
        Dim computerdeep As String
        If CheckBoxhims.Checked = True Then
            computerhims = "มี"
        ElseIf CheckBoxhims.Checked = False Then
            computerhims = "ไม่มี"
        End If
        If CheckBoxpacs.Checked = True Then
            computerpacs = "มี"
        ElseIf CheckBoxpacs.Checked = False Then
            computerpacs = "ไม่มี"
        End If
        If CheckBoxlab.Checked = True Then
            computerlab = "มี"
        ElseIf CheckBoxlab.Checked = False Then
            computerlab = "ไม่มี"
        End If
        If CheckBoxsystem.Checked = True Then
            computersystem = "มี"
        ElseIf CheckBoxsystem.Checked = False Then
            computersystem = "ไม่มี"
        End If
        If CheckBoxadmin.Checked = True Then
            computeradmin = "มี"
        ElseIf CheckBoxadmin.Checked = False Then
            computeradmin = "ไม่มี"
        End If
        If CheckBoxdeep.Checked = True Then
            computerdeep = "มี"
        ElseIf CheckBoxdeep.Checked = False Then
            computerdeep = "ไม่มี"
        End If
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Try
            mySqlCommand.CommandText = "INSERT INTO data_device (type,name,model,c_cpu,c_mainboard,c_ram,c_harddisk,c_vgacard,c_ipnumber,detail,c_ps,c_cd,c_case,serialnumber,c_comname,c_windows,c_office,c_other,price,state_device,computerhims,computerpacs,computerlab,computersystem,computeradmin,computerdeep,date,idDepartment) VALUES ('Computer','" & tab3brand.Text & "', '" & tab3model.Text & "', '" & tab3cpu.Text & "','" & tab3mb.Text & "','" & tab3ram.Text & "','" & tab3hd.Text & "','" & tab3vga.Text & "','" & tab3ipnumber.Text & "','" & tab3detail.Text & "','" & tab3ps.Text & "','" & tab3cd.Text & "','" & tab3case.Text & "','" & tab3serial.Text & "','" & tab3comname.Text & "','" & tab3windows.Text & "','" & tab3office.Text & "','" & tab3other.Text & "','" & tab3price.Text & "','ว่าง','" & computerhims & "','" & computerpacs & "','" & computerlab & "','" & computersystem & "','" & computeradmin & "','" & computerdeep & "','" + Date.Now.ToString + "','0');"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! by โตน ลูกพี่อารี")

            ''เคลียร์ช่องหลังกรอกเสร็จ

            tab3brand.Text = ""
            tab3model.Text = ""
            tab3cd.Text = ""
            tab3cpu.Text = ""
            tab3hd.Text = ""
            tab3mb.Text = ""
            tab3vga.Text = ""
            tab3ram.Text = ""
            tab3ipnumber.Text = ""
            tab3serial.Text = ""
            tab3detail.Text = ""
            tab3ps.Text = ""
            tab3case.Text = ""
            tab3comname.Text = ""
            tab3windows.Text = ""
            tab3office.Text = ""
            tab3other.Text = ""
            tab3price.Text = ""
            CheckBoxhims.Checked = False
            CheckBoxpacs.Checked = False
            CheckBoxlab.Checked = False
            CheckBoxsystem.Checked = False
            CheckBoxadmin.Checked = False
            CheckBoxdeep.Checked = False
        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try
    End Sub
    ''โค้ดปุ่มsave other
    Private Sub btnsaveother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveother.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Try
            mySqlCommand.CommandText = "INSERT INTO data_device (type,name,model,detail,serialnumber,price,state_device,date,idDepartment) VALUES ('Other', '" & tab4brand.Text & "',  '" & tab4model.Text & "','" & tab4detail.Text & "', '" & tab4serial.Text & "','" & tab4price.Text & "','ว่าง','" + Date.Now.ToString + "','0');"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! by โตน ลูกพี่อารี")

            ''เคลียร์ช่องหลังกรอกเสร็จ

            tab4brand.Text = ""
            tab4model.Text = ""
            tab4detail.Text = ""
            tab4serial.Text = ""
            tab4price.Text = ""
        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try
    End Sub
    ''โค้ดปุ่มsave printer 
    Private Sub btnsaveprin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsaveprin.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim printer As String
        If Radiolaserc.Checked = True Then
            printer = "Laser Printer สี"
        End If
        If Radiolaserwb.Checked = True Then
            printer = "Laser Printer ขาว-ดำ"
        End If
        If Radiodot.Checked = True Then
            printer = "Dot-matrix Printer"
        End If
        If Radioinkjet.Checked = True Then
            printer = "Inkjet Printer"
        End If
        If Radiosticker.Checked = True Then
            printer = "Sticker Printer"
        End If
        If Radioinkall.Checked = True Then
            printer = "Inkjet-all in one"
        End If
        If Radiolaserall.Checked = True Then
            printer = "Laser-all in one"
        End If
        If Radiolasermulti.Checked = True Then
            printer = "Laser-multifunction"
        End If
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Try
            mySqlCommand.CommandText = "INSERT INTO data_device (type,name,model,serialnumber,price,detail,p_type,state_device,date,idDepartment) VALUES ('Printer','" & tab2brand.Text & "', '" & tab2model.Text & "','" & tab2serial.Text & "','" & tab2price.Text & "','" & tab2detail.Text & "','" & printer & "','ว่าง','" + Date.Now.ToString + "','0');"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! by โตน ลูกพี่อารี")

            ''เคลียร์ช่องหลังกรอกเสร็จ

            tab2brand.Text = ""
            tab2model.Text = ""
            tab2detail.Text = ""
            tab2serial.Text = ""
            tab2price.Text = ""
            Radiolaserc.Checked = False
            Radiolaserwb.Checked = False
            Radiodot.Checked = False
            Radioinkjet.Checked = False
            Radiosticker.Checked = False
            Radioinkall.Checked = False
            Radiolaserall.Checked = False
            Radiolasermulti.Checked = False
        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try
    End Sub
    ''โค้ดปุ่มsave License 12/6/56 ****************************************************************
    Private Sub btnsavelicense_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavelicense.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim windows_application As String
        If Radioos.Checked = True Then
            windows_application = "OS"
        End If
        If Radioapp.Checked = True Then
            windows_application = "Application"
        End If

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Try
            mySqlCommand.CommandText = "INSERT INTO data_device (type,name,price,detail,amount,windows_application,state_device,date,idDepartment,startbuy,warrant) VALUES ('License','" & tab5brand.Text & "','" & tab5price.Text & "','" & tab5detail.Text & "','" & tab5amount.Text & "','" & windows_application & "','ว่าง','" + Date.Now.ToString + "','0','" & DateTimePicker1.Value.Date.ToString & "','" & DateTimePicker2.Value.Date.ToString & "');"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! by โตน ลูกพี่อารี")

            ''เคลียร์ช่องหลังกรอกเสร็จ

            tab5brand.Text = ""
            tab5amount.Text = ""
            tab5detail.Text = ""
            tab5price.Text = ""
            Radioos.Checked = False
            Radioapp.Checked = False
        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try

    End Sub
    ''โค้ดปุ่มsave Network
    Private Sub btnsavenet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsavenet.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Try
            mySqlCommand.CommandText = "INSERT INTO data_device (type,name,detail,serialnumber,c_ipnumber,pass_connect,pass_config,price,state_device,date,idDepartment) VALUES ('Network', '" & tab6brand.Text & "',  '" & tab6detail.Text & "','" & tab6serial.Text & "', '" & tab6ipnumber.Text & "','" & tab6passconnect.Text & "','" & tab6passconfig.Text & "','" & tab6price.Text & "','ว่าง','" + Date.Now.ToString + "','0');"
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            MsgBox("เก็บเข้าฐานข้อมูลแล้วจ้า!! by โตน ลูกพี่อารี")

            ''เคลียร์ช่องหลังกรอกเสร็จ

            tab6brand.Text = ""
            tab6detail.Text = ""
            tab6serial.Text = ""
            tab6ipnumber.Text = ""
            tab6passconnect.Text = ""
            tab6passconfig.Text = ""
            tab6price.Text = ""
        Catch ex As Exception
            MsgBox(ex.ToString)
            sql.Close()
        End Try
    End Sub


    Private Sub add_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sql = New MySqlConnection
        sql.ConnectionString = "server=" + ipconnect + ";user id=" + usernamedb + ";password=" + mysqlpass + ";database=" + dbname + ";Character Set =utf8;"
        Try
            sql.Open()
            ' MsgBox("CONNECTED TO DATABASE")
        Catch ex As Exception
            MsgBox("Can't Connect to database" + ex.Message)

            Me.Close()
        End Try

    End Sub

    Private Sub แกไขขอมลอปกรToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แกไขขอมลอปกรToolStripMenuItem.Click
        Dim NextForm As Edit2 = New Edit2(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub เพมแผนกToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมแผนกToolStripMenuItem.Click
        Dim NextForm As Adddepartment = New Adddepartment(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณToolStripMenuItem.Click
        Dim NextForm As device_department = New device_department(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณกลมToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณกลมToolStripMenuItem.Click
        Dim NextForm As add_department_group = New add_department_group(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub แกไขแผนกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แกไขแผนกToolStripMenuItem.Click
        Dim NextForm As showdetail = New showdetail(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub บนทกประวตบำรงรกษาToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บนทกประวตบำรงรกษาToolStripMenuItem.Click
        Dim NextForm As historydetail = New historydetail(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelcom.Click
        tab3brand.Text = ""
        tab3model.Text = ""
        tab3cd.Text = ""
        tab3cpu.Text = ""
        tab3hd.Text = ""
        tab3mb.Text = ""
        tab3vga.Text = ""
        tab3ram.Text = ""
        tab3ipnumber.Text = ""
        tab3serial.Text = ""
        tab3detail.Text = ""
        tab3ps.Text = ""
        tab3case.Text = ""
        tab3comname.Text = ""
        tab3windows.Text = ""
        tab3office.Text = ""
        tab3other.Text = ""
        tab3price.Text = ""
        CheckBoxhims.Checked = False
        CheckBoxpacs.Checked = False
        CheckBoxlab.Checked = False
        CheckBoxsystem.Checked = False
        CheckBoxadmin.Checked = False
        CheckBoxdeep.Checked = False
    End Sub

    Private Sub btncencelprin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncencelprin.Click
        tab2brand.Text = ""
        tab2model.Text = ""
        tab2detail.Text = ""
        tab2serial.Text = ""
        tab2price.Text = ""
        Radiolaserc.Checked = False
        Radiolaserwb.Checked = False
        Radiodot.Checked = False
        Radioinkjet.Checked = False
        Radiosticker.Checked = False
        Radioinkall.Checked = False
        Radiolaserall.Checked = False
        Radiolasermulti.Checked = False
    End Sub

    Private Sub btncancelmonitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelmonitor.Click
        tab1model.Text = ""
        tab1brand.Text = ""
        tab1size.Text = ""
        tab1detail.Text = ""
        tab1serial.Text = ""
        tab1price.Text = ""
    End Sub

    Private Sub btncancelother_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelother.Click
        tab4brand.Text = ""
        tab4model.Text = ""
        tab4detail.Text = ""
        tab4serial.Text = ""
        tab4price.Text = ""
    End Sub

    Private Sub btncancellicense_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancellicense.Click
        tab5brand.Text = ""
        tab5amount.Text = ""
        tab5detail.Text = ""
        tab5price.Text = ""
        Radioos.Checked = False
        Radioapp.Checked = False
    End Sub

    Private Sub btncancelnet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancelnet.Click
        tab6brand.Text = ""
        tab6detail.Text = ""
        tab6serial.Text = ""
        tab6ipnumber.Text = ""
        tab6passconnect.Text = ""
        tab6passconfig.Text = ""
        tab6price.Text = ""
    End Sub

    Private Sub บำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บำรงรกษาToolStripMenuItem.Click
        Dim NextForm As addhistory = New addhistory(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub
End Class

